/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.common.util;

import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
import com.ce.pms.exception.BusinessException;

/**
 * 功能描述：从配置文件中加载SQL，并通过getSql方法来获取SQL<br>
 * @author 罗军林 创建日期：2008-9-9
 */
public class SqlConfig {
	private Properties properties;

	private final String SQLPATH="businessSQL/";

	public SqlConfig(String fileName){
		try{
			initSQLXML(SQLPATH+fileName);
		}catch (Exception e) {
			throw new BusinessException("SQL config file is not Found!");
		}
	}

	/**
	 * 功能描述:返回该KEY的SQL<br>
	 * @param key
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public String getSql(String key){
		return properties.getProperty(key);
	}

	/**
	 * 功能描述:装载SQL配置文件<br>
	 * @throws IOException
	 * @throws InvalidPropertiesFormatException<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-29<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private void initSQLXML(String pathFileName) throws IOException, InvalidPropertiesFormatException {
		properties=new Properties();
		ClassPathResource cpr = new ClassPathResource(pathFileName);
        properties.loadFromXML(cpr.getInputStream());
	}
}
